import pandas as pd
import algorithm as al
from sklearn import svm
from sklearn.neighbors import KNeighborsClassifier
from sklearn.ensemble import RandomForestClassifier
from sklearn import tree



from sklearn.model_selection import cross_val_score

tf1 = pd.read_csv('tf1.csv')
tf2 = pd.read_csv('tf2.csv')
c_names = list(tf1.columns)
c_names[0] = 'filename'
c_names[-1] = 'result'

tf1.columns = c_names
tf2.columns = c_names
tf1 = tf1[['filename', 'result']]
tf2 = tf2[['filename', 'result']]
result = pd.DataFrame(columns=['data set', 'score1', 'score2'])

for i in range(tf1.shape[0]):
    p1_features = eval(tf1.iloc[i, 1])
    p2_features = eval(tf2.iloc[i, 1])
    df = al.dataInput(tf1.iloc[i, 0]+'.xlsx')
    X1 = df[p1_features].values
    X2 = df[p2_features].values
    y = df['tag'].values
    # clf = svm.SVC(kernel='linear', C=1) #  svm分类器
    # clf = KNeighborsClassifier() #  knn分类器
    # clf = RandomForestClassifier(n_estimators=8)  # 随机森林
    clf = tree.DecisionTreeClassifier()  # 决策数
    scores1 = cross_val_score(clf, X1, y, cv=10, scoring='accuracy')
    scores2 = cross_val_score(clf, X2, y, cv=10, scoring='accuracy')
    result = result.append(pd.Series([tf1.iloc[i, 0], scores1.mean(), scores2.mean()]),
                            ignore_index=True)

result.to_csv('ac_dt.csv')